package com.jay.lang.reflect.clazz.proxy;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyCls {
	public static void main(String[] args) {
		HelloWorld hw = new HelloWorldImpl();
		InvocationHandler handler = new HelloWorldHandler(hw);
		HelloWorld proxy = (HelloWorld) Proxy.newProxyInstance(hw.getClass()
				.getClassLoader(), hw.getClass().getInterfaces(), handler);
		proxy.sayHelloWorld("You");
		HelloChina proxyC = (HelloChina) Proxy.newProxyInstance(hw.getClass()
				.getClassLoader(), hw.getClass().getInterfaces(), handler);
		proxyC.sayHelloChina("你大爷");

		System.out.println("---------------");
		System.out.println(Proxy.isProxyClass(proxy.getClass()));
		System.out.println(Proxy.getInvocationHandler(proxy));
		Class proxyCls = Proxy.getProxyClass(hw.getClass().getClassLoader(), hw
				.getClass().getInterfaces());
		System.out.println(proxyCls);

		System.out.println("---------------");
		Constructor[] cs = proxyCls.getDeclaredConstructors();
		for (Constructor c : cs) {
			System.out.println(c);
		}

		System.out.println("---------------");
		Field[] fs = proxyCls.getDeclaredFields();
		for (Field f : fs) {
			System.out.println(f);
		}

		System.out.println("---------------");
		Method[] ms = proxyCls.getDeclaredMethods();
		for (Method m : ms) {
			System.out.println(m);
		}

		System.out.println("---------------");
		Class sc = proxyCls.getSuperclass();
		System.out.println(sc);
	}
}
